<template>
    <!--管理员-->
    <div class="role">
        <a-card>
            <div class="table">
                <Tables
                    ref="table"
                    :columns="columns"
                    :loadData="findAddressList"
                    :addData="addAddress"
                    :editData="editAddress"
                    :delData="delAddress"
                    :formColumns="formColumns"
                >
                    <template slot="node_kdt_id" slot-scope="{ text }">
                        <span>{{ formatStore(text) }}</span>
                    </template>
                </Tables>
            </div>
        </a-card>
    </div>
</template>

<script>
import { addAddress, delAddress, editAddress, findAddressList } from '@/api/address'
import { findRoleAll } from '@/api/role'
import rules from '@/validate/admin'

export default {
    name: 'RoleList',
    data() {
        return {
            columns: [
                {
                    dataIndex: 'node_kdt_id',
                    title: '门店',
                    align: 'center',
                    scopedSlots: { customRender: 'node_kdt_id' }
                },
                {
                    dataIndex: 'address',
                    title: '配送中心地址',
                    align: 'center'
                }
            ],
            formColumns: {
                node_kdt_id: {
                    type: 'select',
                    label: '门店',
                    options: [
                        {
                            name: '邮差蛋糕总店',
                            value: '15145249'
                        },
                        {
                            name: '邮差蛋糕（渝中配送中心）',
                            value: '74852863'
                        },
                        {
                            name: '邮差蛋糕（渝北配送中心）',
                            value: '116399626'
                        },
                        {
                            name: '渝北店配送中心',
                            value: '74852864'
                        },
                        {
                            name: '时代店配送中心',
                            value: '119079255'
                        }
                    ]
                },
                address: {
                    type: 'input',
                    label: '配送中心地址'
                },
                id: {
                    type: 'hidden'
                }
            },
            rules: rules,
            stores: {
                15145249: '邮差蛋糕总店',
                74852863: '邮差蛋糕（渝中配送中心）',
                116399626: '邮差蛋糕（渝北配送中心）',
                74852864: '渝北店配送中心',
                119079255: '时代店配送中心'
            },
            findAddressList,
            addAddress,
            editAddress,
            delAddress
        }
    },
    created() {
        this.findRoleAll()
    },
    methods: {
        async findRoleAll() {
            const res = await findRoleAll()
            const { data } = res
            this.$set(this.formColumns.roleId, 'options', data)
        },
        formatStore(id) {
            if (!id) return ''
            return this.stores[id] ?? ''
        }
    }
}
</script>

<style scoped></style>
